﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BHXH.Core.IService;
using FX.Core;
using BHXH.Core.Domain;
using Infragistics.Win.UltraWinGrid;

namespace BHXH.Frm.FrmUserControl
{
    public partial class Dinh_Kem : UserControl
    {
        private readonly Ihs_attachfileService _hs_attachfileSrv;

        public Dinh_Kem()
        {
            InitializeComponent();
            _hs_attachfileSrv = IoC.Resolve<Ihs_attachfileService>();

            LoadGridview_DinhKem();
        }

        public DataTable GetAll_DinhKem_Tab()
        {
            IList<hs_attachfile> a = _hs_attachfileSrv.GetAll_hs_attachfile();
            DataTable table = new DataTable();
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("STT \n(#)", typeof(string));
            table.Columns.Add("Loại giấy tờ, biểu mẫu \n(1)", typeof(string));
            table.Columns.Add("Chọn tệp đính kèm \n(2)", typeof(string));
            table.Columns.Add("Đã hưởng BHXH ", typeof(string));
            table.Columns.Add("Giấy xác nhận thời gian đóng BHTN \nchưa hưởng BHTN", typeof(string));
            table.Columns.Add("Xem \n(...)", typeof(string));

            if (a.Count > 0)
            {
                foreach (var item in a)
                {
                    table.Rows.Add(item.ID, 1, item.TEN_CT, item.FILENAME, item.SoBHXH, null, null);
                }
            }
            else
            {
                table.Rows.Add(1, 1, "Quyết định thành lập hoặc giấy phép kinh doanh/hoạt động (Bản sao có chứng thực)", null, null, null, null);
            }
            
            return table;
        }

        public void LoadGridview_DinhKem()
        {

            uG_DinhKem.DataSource = GetAll_DinhKem_Tab();
            uG_DinhKem.DisplayLayout.Override.ActiveCellAppearance.Reset();
            uG_DinhKem.DisplayLayout.Override.ActiveRowAppearance.Reset();
            uG_DinhKem.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
            this.uG_DinhKem.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout;
            this.uG_DinhKem.DisplayLayout.Bands[0].AutoPreviewMaxLines = 3;
            this.uG_DinhKem.DisplayLayout.Bands[0].Override.AllowRowLayoutLabelSizing = RowLayoutSizing.Both;
            this.uG_DinhKem.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            this.uG_DinhKem.SyncWithCurrencyManager = false;
        }

        public void Ghi_DinhKem()
        {
            hs_attachfile hs = new hs_attachfile();
            UltraGridBand band = this.uG_DinhKem.DisplayLayout.Bands[0];
            foreach (UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow))
            {
                UltraGridColumn column = this.uG_DinhKem.DisplayLayout.Bands[0].Columns[0];
                hs.ID = int.Parse(row.Cells[column].Value.ToString());
                hs.ID_TK = "101";
                hs.TEN_CT = row.Cells[this.uG_DinhKem.DisplayLayout.Bands[0].Columns[2]].Value.ToString();
                hs.FILENAME = row.Cells[this.uG_DinhKem.DisplayLayout.Bands[0].Columns[3]].Value.ToString();
                hs.SoBHXH = row.Cells[this.uG_DinhKem.DisplayLayout.Bands[0].Columns[4]].Value.ToString();
                _hs_attachfileSrv.Update_hs_attachfile(hs);
            }
        }
    }
}
